<template>
  <div class="app-container">
    <div style="display: flex;flex-flow: row nowrap;margin-left: 9%;">
      <div style="border:1px;background-color: #4e8dff; width: 6px;height: 20px"></div>
      <span style="margin-left: 10px">{{ ruleTitle }}</span>
    </div>
    <el-form v-loading="formLoading" ref="baseForm" :model="rulesForm" label-width="100px"
             style="margin-left: 25%;">

      <!--   优秀-->
      <el-row>
        <el-col :span="16">
          <span class="rule-title">优秀</span>
          <el-form-item label="积分" prop="excellentScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.excellentScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="荣誉值" prop="excellentHonorScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.excellentHonorScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="人数占比" prop="excellentPersonScale">
            <el-input :disabled="isDisabled" v-model="rulesForm.excellentPersonScale" placeholder="未设置">
              <i
                class="el-icon-my-scale el-input__icon"
                slot="suffix"
              >
              </i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!--    良好-->
      <el-row>
        <el-col :span="16">
          <span class="rule-title">良好</span>
          <el-form-item label="积分" prop="goodScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.goodScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="荣誉值" prop="goodHonorScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.goodHonorScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="人数占比" prop="goodPersonScale">
            <el-input :disabled="isDisabled" v-model="rulesForm.goodPersonScale" placeholder="未设置">
              <i
                class="el-icon-my-scale el-input__icon"
                slot="suffix"
              >
              </i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 称职-->
      <el-row>
        <el-col :span="16">
          <span class="rule-title">称职</span>
          <el-form-item label="积分" prop="qualifiedScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.qualifiedScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="荣誉值" prop="qualifiedHonorScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.qualifiedHonorScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="人数占比" prop="qualifiedPersonScale">
            <el-input :disabled="isDisabled" v-model="rulesForm.qualifiedPersonScale" placeholder="未设置">
              <i
                class="el-icon-my-scale el-input__icon"
                slot="suffix"
              >
              </i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="16">
          <span class="rule-title">基本称职</span>
          <el-form-item label="积分" prop="almostScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.almostScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="荣誉值" prop="almostHonorScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.almostHonorScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="人数占比" prop="almostPersonScale">
            <el-input :disabled="isDisabled" v-model="rulesForm.almostPersonScale" placeholder="未设置">
              <i
                class="el-icon-my-scale el-input__icon"
                slot="suffix"
              >
              </i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!-- 不称职-->
      <el-row>
        <el-col :span="16">
          <span class="rule-title">不称职</span>
          <el-form-item label="积分" prop="unqualifiedScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.unqualifiedScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="荣誉值" prop="unqualifiedHonorScore">
            <el-input :disabled="isDisabled" v-model="rulesForm.unqualifiedHonorScore"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="16">
          <el-form-item label="人数占比" prop="unqualifiedPersonScale">
            <el-input :disabled="isDisabled" v-model="rulesForm.unqualifiedPersonScale" placeholder="未设置">
              <i
                class="el-icon-my-scale el-input__icon"
                slot="suffix"
              >
              </i>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <div style="display: flex;flex-flow: row nowrap;margin-left: 9%">
      <div style="border:1px;background-color: #4e8dff; width: 6px;height: 20px"></div>
      <span style="margin-left: 10px">{{ receiveTitle }}</span>
    </div>
    <el-form v-loading="formLoading" ref="baseForm" :model="receiveForm" label-width="100px"
             style="margin-left: 25%;">

      <!--人员选择-->
      <el-row>
        <el-col :span="16">
          <el-form-item :label="labelName" :class="{'is-required':!isDisabled}">
            <org-users :useTreeAll="useTreeAll" :isDisabled="isDisabled" :pickArray="personPickMapList" @outValue="getReceiveData"></org-users>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

  </div>
</template>

<script>
import {listRules} from "@/api/system/rules/rulesApi";
import OrgUsers from "../../components/OrgUsers/index"
import {getTask} from "@/api/examine/task/api";
import {getExamineInfo} from "@/api/examine/user/api";

export default {
  name: "commonForm",
  dicts: ['examine_receive_type'],
  components: {
    OrgUsers
  },
  props: {
    labelName: {
      type: String
    },
    isDisabled: {
      type: Boolean,
      default: false
    },
    isUpdate: {
      type: Boolean,
      default: false
    },
    ruleType: {
      type: Number
    },
    ruleTitle: {
      type: String
    },
    receiveTitle: {
      type: String
    },
    examineId: {
      type: String
    },
    useTreeAll: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formLoading:false,
      rulesForm: {},
      receiveForm: {},
      personPickMapList: []
    }
  },
  created() {
    this.getRulesSetting()
  },
  methods: {
    getCommonForm() {
      return new Promise((resolve, reject) => {
        if (this.personPickMapList.length > 0) {
          this.receiveForm.personPickMapList = this.personPickMapList;
          resolve(Object.assign(this.rulesForm, this.receiveForm))
        } else {
          this.$modal.msgError('请选择'+this.labelName);
          reject(false)
        }
      })
    },
    getRulesSetting() {
      if (!this.isUpdate) {
        this.formLoading = true
        listRules({pageNum: 1, pageSize: 100, rulesType: this.ruleType}).then(resp => {
          if (resp.rows) {
            var almostObj = resp.rows.find(obj => obj.status == 4);
            var excellentObj = resp.rows.find(obj => obj.status == 3);
            var goodObj = resp.rows.find(obj => obj.status == 2);
            var qualifiedObj = resp.rows.find(obj => obj.status == 1);
            var unQualifiedObj = resp.rows.find(obj => obj.status == 0);
            var tempObj = {};
            if (excellentObj) {
              tempObj.excellentScore = excellentObj.score;
              tempObj.excellentHonorScore = excellentObj.honorScore;
              tempObj.excellentPersonScale = excellentObj.personScale;
            }
            if (goodObj) {
              tempObj.goodScore = goodObj.score;
              tempObj.goodHonorScore = goodObj.honorScore;
              tempObj.goodPersonScale = goodObj.personScale;
            }
            if (qualifiedObj) {
              tempObj.qualifiedScore = qualifiedObj.score;
              tempObj.qualifiedHonorScore = qualifiedObj.honorScore;
              tempObj.qualifiedPersonScale = qualifiedObj.personScale;
            }
            if (unQualifiedObj) {
              tempObj.unqualifiedScore = unQualifiedObj.score;
              tempObj.unqualifiedHonorScore = unQualifiedObj.honorScore;
              tempObj.unqualifiedPersonScale = unQualifiedObj.personScale;
            }
            if (almostObj) {
              tempObj.almostScore = almostObj.score;
              tempObj.almostHonorScore = almostObj.honorScore;
              tempObj.almostPersonScale = almostObj.personScale;
            }
            this.rulesForm = tempObj
          }
        }).finally(() => {
          this.formLoading = false
        })
      } else {
        this.formLoading = true
        getExamineInfo(this.examineId).then(resp => {
          var rulesObj = {};
          rulesObj.excellentScore = resp.data.excellentScore
          rulesObj.excellentHonorScore = resp.data.excellentHonorScore
          rulesObj.excellentPersonScale = resp.data.excellentPersonScale
          rulesObj.goodScore = resp.data.goodScore
          rulesObj.goodHonorScore = resp.data.goodHonorScore
          rulesObj.goodPersonScale = resp.data.goodPersonScale
          rulesObj.qualifiedScore = resp.data.qualifiedScore
          rulesObj.qualifiedHonorScore = resp.data.qualifiedHonorScore
          rulesObj.qualifiedPersonScale = resp.data.qualifiedPersonScale
          rulesObj.unqualifiedScore = resp.data.unqualifiedScore
          rulesObj.unqualifiedHonorScore = resp.data.unqualifiedHonorScore
          rulesObj.unqualifiedPersonScale = resp.data.unqualifiedPersonScale
          rulesObj.almostScore = resp.data.almostScore
          rulesObj.almostHonorScore = resp.data.almostHonorScore
          rulesObj.almostPersonScale = resp.data.almostPersonScale
          rulesObj.receiveType = resp.data.receiveType
          this.rulesForm = rulesObj;
          var receiveObj = {};
          receiveObj.receiveType = String(resp.data.receiveType)
          this.receiveForm = receiveObj
          this.personPickMapList = JSON.parse(resp.data.receivePickJson)
        }).finally(() => {
          this.formLoading = false
        })
      }
    },
    // 接受人员
    getReceiveData(value) {
      this.personPickMapList = value
    }
  }
}
</script>

<style scoped>
.rule-title {
  margin-left: 100px;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  display: inline-block;
}
</style>
